programming4us
           
 
 
Windows

Windows 7 : Scripting Windows with PowerShell - Getting Started with PowerShell

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
5/4/2011 6:20:02 PM
Windows 7 ships with PowerShell 2.0 installed and ready for action, so you can start scripting right away. Although that term generally means something like “entering multiple statements or commands in a file that you can then execute all at once,” things are a bit different in the PowerShell world. What I mean is that when you’re at the PowerShell command line, you can execute single commands, as you can using Command Prompt, but you can also run through an entire script by executing multiple, consecutive commands. For example, you can run one command that stores data in a variable, and then you can run another command later on that includes that variable.

So when you’re executing commands in a PowerShell session, you’re essentially always executing a script, even if it’s a script that contains only a single command.

Starting a PowerShell Session

To get PowerShell up and running, select Start, type power, and then select Windows PowerShell in the search results. Windows 7 starts a new PowerShell console session, and displays it in the Windows PowerShell window, as shown in Figure 1.

Figure 1. Windows PowerShell is eerily similar to Command Prompt.

As you can see, on the surface PowerShell looks like a Command Prompt clone with its character-based console and command-line prompt. In fact, not only does PowerShell look like Command Prompt, it also works like Command Prompt. That is, almost anything you can do in a Command Prompt session you can also do in exactly the same way in a PowerShell session:

  • PowerShell supports the standard Command Prompt commands, including cd, del, dir, echo, md, move, ren, rm, rmdir, set, sort, and start.

  • PowerShell supports the standard DOSKEY techniques for recalling command lines and running multiple commands at once.

  • You can use PowerShell to start batch files, script, and programs.

  • PowerShell supports redirection (such as >) and piping (|).

  • You can use PowerShell’s system menu (click the icon in the upper-left corner of the window) to select, copy, and paste text, just as with the Command Prompt window.

All this means that if you’re comfortable working with Command Prompt, you won’t have much of a learning curve when it comes to PowerShell (at least as far as the above techniques are concerned).

Understanding PowerShell Cmdlets

What truly separates PowerShell from Command Prompt is the concept of the cmdlet (pronounced “commandlet”), which is a PowerShell component that encapsulates some larger functionality into a single item. (If you’re familiar with Excel, a cmdlet is analogous to an Excel worksheet function.) The name of each PowerShell cmdlet takes the following general form:

verb-subject

Here, subject refers to some kind of object, and verb is some action that the cmdlet performs on that object. For example, you can use the Get-Host cmdlet to return information about the current PowerShell hosting environment, or you can use the Out-File cmdlet to output data to a file.


Although you can run most cmdlets with no other text, most of the time you’ll augment a cmdlet name with various parameters, depending on the cmdlet syntax. For example, you use the Write-Host cmdlet to write text to the hosting environment (which means the command line in a PowerShell console session), so you need to specify the text you want to write, as in this example:

write-host "Hello PowerShell World!"

I should also mention here that many cmdlets have alternate names called aliases that you can use. For example, the Get-Service cmdlet returns the current status of whatever service you specify, as in this example:

get-service w32time

However, Get-Service also uses the alias gsv, the following command is equivalent:

gsv w32time

Table 1 lists the PowerShell aliases

Table 1. Cmdlet Aliases Used By PowerShell
AliasCmdlet
%ForEach-Object
?Where-Object
acAdd-Content
asnpAdd-PSSnapIn
catGet-Content
cdSet-Location
chdirSet-Location
clcClear-Content
clearClear-Host
clhyClear-History
cliClear-Item
clpClear-ItemProperty
clsClear-Host
clvClear-Variable
compareCompare-Object
copyCopy-Item
cpCopy-Item
cpiCopy-Item
cppCopy-ItemProperty
isepowershell_ise.exe
iwmiInvoke-WMIMethod
killStop-Process
lpOut-Printer
lsGet-ChildItem
manhelp
mdmkdir
measureMeasure-Object
miMove-Item
mountNew-PSDrive
moveMove-Item
mpMove-ItemProperty
mvMove-Item
nalNew-Alias
ndrNew-PSDrive
niNew-Item
nmoNew-Module
nsnNew-PSSession
nvNew-Variable
cvpaConvert-Path
dbpDisable-PSBreakpoint
delRemove-Item
diffCompare-Object
dirGet-ChildItem
ebpEnable-PSBreakpoint
echoWrite-Output
epalExport-Alias
epcsvExport-Csv
epsnExport-PSSession
eraseRemove-Item
etsnEnter-PSSession
exsnExit-PSSession
fcFormat-Custom
flFormat-List
foreachForEach-Object
ftFormat-Table
fwFormat-Wide
galGet-Alias
gbpGet-PSBreakpoint
gcGet-Content
gciGet-ChildItem
gcmGet-Command
gcsGet-PSCallStack
gdrGet-PSDrive
ghyGet-History
ogvOut-GridView
ohOut-Host
popdPop-Location
psGet-Process
pushdPush-Location
pwdGet-Location
rInvoke-History
rbpRemove-PSBreakpoint
rcjbReceive-Job
rdRemove-Item
rdrRemove-PSDrive
renRename-Item
riRemove-Item
rjbRemove-Job
rmRemove-Item
rmdirRemove-Item
rmoRemove-Module
rniRename-Item
rnpRename-ItemProperty
rpRemove-ItemProperty
rsnRemove-PSSession
rsnpRemove-PSSnapin
rvRemove-Variable
rvpaResolve-Path
rwmiRemove-WMIObject
sajbStart-Job
giGet-Item
gjbGet-Job
glGet-Location
gmGet-Member
gmoGet-Module
gpGet-ItemProperty
gpsGet-Process
groupGroup-Object
gsnGet-PSSession
gsnpGet-PSSnapIn
gsvGet-Service
guGet-Unique
gvGet-Variable
gwmiGet-WmiObject
hGet-History
historyGet-History
icmInvoke-Command
iexInvoke-Expression
ihyInvoke-History
iiInvoke-Item
ipalImport-Alias
ipcsvImport-Csv
ipmoImport-Module
ipsnImport-PSSession
salSet-Alias
sapsStart-Process
sasvStart-Service
sbpSet-PSBreakpoint
scSet-Content
selectSelect-Object
setSet-Variable
siSet-Item
slSet-Location
sleepStart-Sleep
sortSort-Object
spSet-ItemProperty
spjbStop-Job
sppsStop-Process
spsvStop-Service
startStart-Process
svSet-Variable
swmiSet-WMIInstance
teeTee-Object
typeGet-Content
whereWhere-Object
wjbWait-Job
writeWrite-Output

Note

Notice that all the standard Command Prompt commands—including cd, del, dir, echo, md, move, ren, rm, rmdir, set, sort, and start—are actually aliases of PowerShell cmdlets (Set-Location, Remove_Item, Get-ChildItem, and so on).

Other -----------------
- Scripting Windows 7 with WSH : Programming the Windows Management Instrumentation Service
- Scripting Windows 7 with WSH : Scripting Internet Explorer
- Scripting Windows 7 with WSH : Programming the WshNetwork Object
- Scripting Windows 7 with WSH : Programming the WshShell Object (part 2)
- Scripting Windows 7 with WSH : Programming the WshShell Object (part 1)
- Scripting Windows 7 with WSH : Programming the WScript Object
- Scripting Windows 7 with WSH : Programming Objects
- Scripting Windows 7 with WSH : Scripts and Script Execution
- Adding Macs to Your Windows 7 Network : Letting Windows Computers See Your Mac Shares
- Adding Macs to Your Windows 7 Network : Using a Mac to Make a Remote Desktop Connection to Windows 7
- Adding Macs to Your Windows 7 Network : Connecting to a Windows Shared Folder
- Adding Macs to Your Windows 7 Network : Connecting to the Windows Network
- Windows 7 : Controlling and Customizing Your Website (part 5) - Viewing the Server Logs
- Windows 7 : Controlling and Customizing Your Website (part 4) - Disabling Anonymous Access
- Windows 7 : Controlling and Customizing Your Website (part 3) - Working Without a Default Document
- Windows 7 : Controlling and Customizing Your Website (part 2) - Setting the Website’s Default Document
- Windows 7 : Controlling and Customizing Your Website (part 1)
- Windows 7 : Adding Folders and Files to the Default Website (part 3) - Adding a Folder to the Default Website
- Windows 7 : Adding Folders and Files to the Default Website (part 2) - Changing the Default Website Home Page
- Windows 7 : Adding Folders and Files to the Default Website (part 1) - Setting Permissions on the Default Website Folder
 
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us